<template>
	<view class="fui-wrap">
		<fui-list>
			<fui-list-cell v-for="(item,index) in list" :key="index">
				<view class="line">
					<view class="line1">
						<fui-text :text="`${item.message}`" :color="item.color" size="28" block></fui-text>
						<view class="img" v-if="item.img" >
							<image :src="item.img" mode="widthFix" style="100%"></image>
						</view>
					</view>
					<fui-text :text="item.nickname" size="28" block></fui-text>
				</view>
			</fui-list-cell>
		</fui-list>
		<fui-empty v-if="list.length===0" :src="`${baseUrl}assets/img/miniapp/empty.png`" title="暂无数据!" :marginTop="200"></fui-empty>
		<filter :param="param" @confirm="doSubmit"></filter>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	import filter from '@/components/common/filter.vue';
	export default {
		components:{
			filter:filter
		},
		data() {
			return {
				baseUrl:baseUrl,
				list:[],
				page:1,
				endData:false,
				param:{
					radio:{value:0,options:['全部','人工开关闸']},
					plate_number:'',
					starttime:'',
					endtime:'',
				}
			}
		},
		onLoad(e) {
			this.getList();
		},
		onReachBottom() {
			this.getList();
		},
		onPullDownRefresh() {
			this.list=[];
			this.page=1;
			this.endData=false;
			this.getList(function(){
				uni.stopPullDownRefresh();
			});
		},
		methods: {
			...methods,
			doSubmit:function(param){
				this.param=param;
				this.list=[];
				this.page=1;
				this.endData=false;
				this.getList();
			},
			getList:function(callback=false){
				this.showPopup=false;
				if(this.endData){
					this.$msg('已经到底了');
					return;
				}
				let {radio,plate_number,starttime,endtime}=this.param;
				this.$get('parking/common/log',{
					radio:radio.value,
					plate_number,
					starttime,
					endtime,
					page:this.page
				},true).then(res=>{
					res=res.map(tf=>{
						let preg1='<br><img .*?/><br>';
						let preg2='<img .*?/>';
						let img='';
						let imgs=tf.message.match(new RegExp(preg2,'g'));
						if(imgs){
						    for(let i=0;i<imgs.length;i++){
						        img=imgs[i];
						        let preg3='src=".*?"';
						        let src=img.match(new RegExp(preg3,'g'));
						        img=src[0].substring(5,src[0].length-1);
						    }
						}
						//替换正则表达式为空
						tf.message=tf.message.replace(new RegExp(preg1,'g'),'');
						tf.img=img;
						return tf;
					});
					this.list=this.list.concat(res);
					this.page++;
					if(res.length<10){
						this.endData=true;
					}	
					if(callback){
						callback();
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
.line{
	display: flex;
	justify-content: space-between;
	align-items: center;
	width:100%;
	.line1{
		display: flex;
		flex-direction: column;
		.img{
			width: 80%;
			margin-top: 10rpx;
		}
	}
}
</style>